package lumis.portal.presentation.perspective;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import lumis.portal.presentation.core.HTMLFragmentComponent;
/**
 * 
 * Default implementation for IPortalMode.
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public  class DefaultPortalMode implements IPortalModeSPI
{
	/**
	 * @since 6.0.0
	 */
	private static final long serialVersionUID = 7423007123502326904L;

	/**
	 * A set of PortalMode's attributes.
	 * @since 6.0.0
	 */
	private Set<String> attributeNames = Collections.emptySet();
	
	/**
	 * PortalMode description
	 * @since 6.0.0
	 */
	private String description;
	
	/**
	 * Value that represents the old portal mode (0 - user, 1 - adminstration/F12).
	 * Current values are: 0 - user, 1 - admin, 2 - publisher
	 * @since 6.0.0
	 */
	private int id;
	
	/**
	 * Key for PortalMode Name.
	 * @since 6.0.0  
	 */
	private String name;
	
	/**
	 * Permission provider of the mode.
	 * @since 6.0.0 
	 */
	private IPermissionProvider permissionProvider;
	
	/**
	 * @since 6.0.0
	 */
	private Perspective perspective;
	
	/**
	 * @since 6.0.0
	 */
	private Class<? extends HTMLFragmentComponent> renderComponentClass;
	
	/**
	 * Constructor for the class.
	 * @param id the id of the current PortalMode
	 * @param name the name of the current PortalMode.
	 * @param description the description of the current PortalMode.
	 * @param attributeNames attribute names for the current PortalMode.
	 * @since 6.0.0
	 */
	public DefaultPortalMode( int id, String name, String description, IPermissionProvider permissionProvider, Class<? extends HTMLFragmentComponent> renderComponentClass, String [] attributeNames)
	{
		this.attributeNames = Collections.unmodifiableSet( new LinkedHashSet<String>(Arrays.asList(attributeNames)));
		this.description = description;
		this.id = id;
		this.name = name;
		this.permissionProvider = permissionProvider;
		this.renderComponentClass = renderComponentClass;
	}
	
	/**
	 * Returns the set of attribute names for the current PortalMode.
	 * @return the set of attribute names for the current PortalMode.
	 * @since 6.0.0
	 */
	public Set<String> getAttributeNames()
	{
		return this.attributeNames;
	}
	
	/**
	 * Returns the description of the current PortalMode.
	 * @return the description of the current PortalMode.
	 * @since 6.0.0
	 */
	public String getDescription() 
	{
		return this.description;
	}
	
	/**
	 * Returns the id of the current PortalMode.
	 * @return the id of the current PortalMode.
	 * @since 6.0.0
	 */
	public int getId()
	{
		return this.id;
	}
	
	/**
	 * Returns the name of the current PortalMode.
	 * @return the name of the current PortalMode.
	 * @since 6.0.0
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * Returns the permission provider of the current PortalMode.
	 * @return the permission provider of the current PortalMode.
	 * @since 6.0.0
	 */
	public IPermissionProvider getPermissionProvider()
	{
		return this.permissionProvider;
	}
	
	/**
	 * Returns the name of the current PortalMode.
	 * @return the name of the current PortalMode.
	 * @since 6.0.0
	 */
	public Perspective getPerspective()
	{
		return perspective;
	}
	
	/**
	 * Sets the new perspective.
	 * @param perspective the wished perspective.
	 * @since 6.0.0
	 */
	void setPerspective(Perspective perspective)
	{
		this.perspective = perspective;
	}
	
	/**
	 * Returns the render component
	 * @since 6.0.0
	 */
	public Class<? extends HTMLFragmentComponent> getRenderComponentClass()
	{
		return this.renderComponentClass;
	}
	
}
